package com.learn.sms.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.learn.sms.core.client.SmsClient;
import com.learn.sms.core.client.SmsClientFactory;
import com.learn.sms.core.client.dto.SmsReceiveRespDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Yu.Tan
 * @date : 2023/7/27 15:42
 * @desc : this class for xxxxx
 **/
@Service
public class SmsSendServiceImpl implements SmsSendService {

    @Resource
    private SmsClientFactory smsClientFactory;

    @Override
    public void receiveSmsStatus(String channelCode, String text) throws Throwable {
        // 获得渠道对应的 SmsClient 客户端
        SmsClient smsClient = smsClientFactory.getSmsClient(channelCode);
        Assert.notNull(smsClient, "短信客户端({}) 不存在", channelCode);
        // 解析内容
        List<SmsReceiveRespDTO> receiveResults = smsClient.parseSmsReceiveStatus(text);
        if (CollUtil.isEmpty(receiveResults)) {
            return;
        }
        // TODO  更新短信日志的接收结果. 因为量一般不大，所以先使用 for 循环更新
    }
}
